import BaseApi from '@/api/baseApi';
import {ID, PARAMS} from '@/api/http';
import FileInfo from '@/structure/fileInfo';
import User from '@/structure/user';

/**
 * 用户
 */
class UserApi extends BaseApi<User> {
  public getBase(): string {
    return 'user/user/user';
  }

  public getIdFieldName(): string {
    return 'userId';
  }

  /**
   * 上传头像
   * @param data 用户
   * @return 文件信息
   */
  // noinspection JSUnusedGlobalSymbols
  public uploadAvatar(data: File): Promise<FileInfo> {
    return super.post0(`${this.getBase()}/uploadAvatar`, data);
  }

  /**
   * 删除头像
   * @param id 用户ID
   * @return 用户信息
   */
  public deleteAvatar(id: ID): Promise<User> {
    return super.post0(`${this.getBase()}/${id}/deleteAvatar`);
  }

  /**
   * 导出excel
   * @param params 参数
   * @return 响应
   */
  public exportExcel(params: PARAMS): Promise<Blob> {
    return super.get0(`${this.getBase()}/exportExcel`, {
      responseType: 'blob',
      params
    });
  }
}

export default new UserApi();
